<?php
namespace Home\Controller;
class DaochuController extends CommonController {
public function _initialize()
{
	set_time_limit(0);
	$this->Is_login();        //检测用户登录信息,如果错误直接返回错误,终止程序
	// $this->Is_power("money");        //检测用户权限,如果错误直接返回错误,终止程序
	$this->assign('heardadminData',session('heardadminData'));
	$this->start = "2018-01-01";
	$this->end = "2018-07-01";
	$this->time = "201801-06";
}
	public function export(){
		$this->display();
	}
	public function daochu(){
		$this->strat = !empty(I('post.strat')) ? strtotime(I('post.strat')) : $this->error('参数错误1',"",1);
		$this->end = !empty(I('post.end')) ? strtotime(I('post.end')) : $this->error('参数错误2',"",1);
		$datatype = !empty(I('post.datatype')) || I('post.datatype')!=0 ? I('post.datatype') : $this->error('参数错误3',"",1);
		p($_POST);
		switch ($datatype) {
			case '1':$this->user();break;
			default:$this->error('参数错误4',"",1);break;
		}
	}
	// 导出主播
	public function user()
	{
		// echo ":".$this->strat."|".$this->end;exit();
		// !empty($this->strat) ? $this->strat : $this->error('参数错误5',"",1);
		// !empty($this->end) ? $this->end : $this->error('参数错误6',"",1);
			// $where['releasetime'] = array("BETWEEN",array($this->strat,$this->end));
			header("Content-type:application/vnd.ms-excel");
			header("Content-Disposition:filename=主播数据.xls");

			$strexport="编号\t昵称\t手机号\t年龄\t性别\t等级(分)\t信用分\t是否绑定微信\t是否认证\t余额\t邀请人昵称\t成功订单数量\r";
			// 查询数据
			$list = M("member m")
			->join("__WECHAT__ w ON m.uuid = w.uuid","LEFT")
			->field("m.uuid,m.nickname,m.username,m.sex,m.age,m.level,m.score,w.openid,m.authentication,m.balance,m.invitecode")
			->where("m.status = 9")
			->order('uuid asc')
			->select();

			$data = M('invite')->select();

			foreach ($list as &$row){
					$row['sex'] = $row['sex'] == 1 ? '男' : '女';
					$row['openid'] = $row['openid'] == '' ? '未绑定' : '已绑定';
					$row['authentication'] = $row['authentication'] == 1 ? '是' : '否';
					switch ($row['level']) {
						case $row['level'] > 80:
							$row['level'] = '(A)'.$row['level'];
							break;
						case $row['level'] > 50:
							$row['level'] = '(B)'.$row['level'];
							break;
						default:
							$row['level'] = '(C)'.$row['level'];
							break;
					}
					foreach ($data as &$vo) {
						if($vo['uuid'] == $row['uuid']){
							$row['name'] = M('member')->where(array('uuid'=>$vo['inviteid']))->find()['nickname'];
						}
					}
					$row['ordercount'] = M('theorder')->where("(state = 3 or state = 4) and uuid = ".$row['uuid'])->count();
					$strexport.=$row['uuid']."\t";
					$strexport.=$row['nickname']."\t";
					$strexport.=$row['username']."\t";
					$strexport.=$row['age']."\t";
					$strexport.=$row['sex']."\t";
					$strexport.=$row['level']."\t";
					$strexport.=$row['score']."\t";
					$strexport.=$row['openid']."\t";
					$strexport.=$row['authentication']."\t";
					$strexport.=$row['balance']."\t";
					$strexport.=$row['name']."\t";
					$strexport.=$row['ordercount']."\r";

			}
			$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
			$this->adminlog("导出主播数据");

			exit($strexport);
	}
	// 导出主播
	public function theorder()
	{
			header("Content-type:application/vnd.ms-excel");
			header("Content-Disposition:filename=订单数据.xls");

			$strexport="订单编号\t自媒体名称\t标题\t订单类型\t播报类型\t等级\t字数\t性别\t价格\t支付方式\t背景音\t自选\t下单时间\t接单主播\t新人\t状态\t相应次数\t交单时间\t结算时间\r";
			// 查询数据
			$data = json_decode(RedisGet('wechat'),true);
			$db_theorder = M("theorder o");
			$where = "(state=3 or state=4) and isdummy=0 and issend=0";
			$orderinfo = $db_theorder->where($where)->join('__MEDIA__ m ON o.mid = m.id','LEFT')->join('__SYSTEMSETUP__ s ON o.level = s.id','LEFT')->join('__WEMEDIAINCOME__ i ON o.number = i.number','LEFT')->field('o.id,o.mid,o.type,o.releasetime,o.title,o.state,o.attribute,o.number,o.uuid,o.words,o.demand,o.linkaudio,o.money,o.premium,o.sex,o.is_pay,o.bgmid,o.ischose,o.newsingle,o.linkaudiotime,o.scoretime,m.media_name mname,s.message level_type,i.status')->order('id desc')->limit($p->firstRow, $p->listRows)->select();
			foreach ($orderinfo as $key => &$value) {
				$value['attempts'] = $data[$value['id']]['count'];
				$value['usemoney'] = $value['money'];
				if($value['demand'] == 2) {
					$value['usemoney'] = $value['money']+$value['premium'];
				}
				$value['usemoney'] = $value['bgmid']!=0?($value['usemoney']*2+20):($value['usemoney']*2);
				switch ($value['status']) {
					case '3':$value['paytype'] = "余额";break;
					case '4':$value['paytype'] = "微信";break;
					case '5':$value['paytype'] = "支付宝";break;
					case '7':$value['paytype'] = "字数";break;
					default:$value['paytype'] = "余额";break;
				}
				switch ($value['type']) {
					case '0':$value['type'] = "讲述类";break;
					case '1':$value['type'] = "情感类";break;
					case '2':$value['type'] = "演绎类";break;
					case '3':$value['type'] = "新闻类";break;
					case '4':$value['type'] = "英文类";break;
					default:$value['type'] = "讲述类";break;
				}
				switch ($value['sex']) {
					case '0':$value['sex'] = "全部";break;
					case '1':$value['sex'] = "男";break;
					case '2':$value['sex'] = "女";break;
				}
				$strexport.=$value['number']."\t";
				$strexport.=$value['mname']."\t";
				$strexport.=$value['title']."\t";
				$strexport.=$value['attribute']==0?"实时\t":"签约\t";
				$strexport.=$value['type']."\t";
				$strexport.=$value['level_type']."\t";
				$strexport.=$value['words']."\t";
				$strexport.=$value['sex']."\t";
				$strexport.=$value['usemoney']."\t";
				$strexport.=$value['paytype']."\t";
				$strexport.=$value['bgmid']==0?"无\t":"有\t";
				$strexport.=$value['ischose']==0?"否\t":"是\t";
				$strexport.=date("Y-m-d H:i:s",$value['releasetime'])."\t";
				$strexport.=$value['uuid']."\t";
				$strexport.=$value['newsingle']."\t";
				$strexport.=$value['state']."\t";
				$strexport.=$value['attempts']."\t";
				$strexport.=date("Y-m-d H:i:s",$value['linkaudiotime'])."\t";
				$strexport.=date("Y-m-d H:i:s",$value['scoretime'])."\r";
			}
		$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
			$this->adminlog("导出订单数据");
		exit($strexport);
	}
	// 导出订单
	public function orderdata()
	{
			header("Content-type:application/vnd.ms-excel");
			header("Content-Disposition:filename=".$this->time."订单数据.xls");

			$strexport="订单编号\t自媒体名称\t标题\t订单类型\t播报类型\t订单等级\t字数\twav时长\t下单性别\t背景音\t自选\t下单时间\t客户支付金额\t支付方式\t主播编号\t主播性别\t主播等级\t结算比例\t主播收入\t交单时间\r";
			// 查询数据
			$db_theorder = M("theorder o");
			$where['o.releasetime'] = array("BETWEEN",array(strtotime($this->start),strtotime($this->end)));
			$orderinfo = $db_theorder->where("state=4 and isdummy=0 and attribute!=3")->where($where)->join('__MEDIA__ m ON o.mid = m.id','LEFT')->join('__WEMEDIAINCOME__ i ON o.number = i.number','LEFT')->join('__MEMBER__ u ON o.uuid = u.uuid','LEFT')->join('__SYSTEMSETUP__ s ON o.level = s.id','LEFT')->field('o.id,o.mid,o.type,o.releasetime,o.title,o.state,o.attribute,o.number,o.uuid,o.words,o.demand,o.linkaudio,o.originalaudio,o.money,o.premium,o.sex ordersex,o.is_pay,o.bgmid,o.ischose,o.newsingle,o.linkaudiotime,o.issend,m.media_name mname,s.message level_type,i.status,u.sex usersex,u.level,u.proportion')->order('o.id desc')->select();
			// p($orderinfo);exit();
			$leveldatadesc = M("systemsetup")->where(array("type"=>1))->order('value desc')->select();
			foreach ($orderinfo as $key => &$value) {
				$value['usemoney'] = $value['money'];
				if($value['demand'] == 2) {
					$value['usemoney'] = $value['money']+$value['premium'];
				}
				$value['usemoney'] = $value['bgmid']!=0?($value['usemoney']*2+20):($value['usemoney']*2);
				if ($value['issend'] == 1) {
					$value['usemoney'] = "4.5";
				}
				switch ($value['status']) {
					case '3':$value['paytype'] = "余额";break;
					case '4':$value['paytype'] = "微信";break;
					case '5':$value['paytype'] = "支付宝";break;
					case '7':$value['paytype'] = "字数";break;
					default:$value['paytype'] = "余额";break;
				}
				switch ($value['type']) {
					case '0':$value['type'] = "讲述类";break;
					case '1':$value['type'] = "情感类";break;
					case '2':$value['type'] = "演绎类";break;
					case '3':$value['type'] = "新闻类";break;
					case '4':$value['type'] = "英文类";break;
					default:$value['type'] = "讲述类";break;
				}
				switch ($value['ordersex']) {
					case '0':$value['ordersex'] = "全部";break;
					case '1':$value['ordersex'] = "男";break;
					case '2':$value['ordersex'] = "女";break;
				}
				switch ($value['usersex']) {
					case '1':$value['usersex'] = "男";break;
					case '2':$value['usersex'] = "女";break;
				}
				$value['durationtime'] = 0;
				if ($value['attribute']==1) {
					$value['durationtime'] = (int)json_decode(do_curl($value['originalaudio'].'?avinfo'),true)['format']['duration'];
					$value['proportion'] = $value['proportion']."元/小时";
				}else{
					$value['proportion'] = "无";
				}
				switch ($value['attribute']) {
					case '0':$value['attribute'] = "实时单";break;
					case '1':$value['attribute'] = "签约单";break;
					case '2':$value['attribute'] = "派发单";break;
				}
				switch ($value['level']) {
					case $value['level'] > 80:$value['level'] = '(A)'.$value['level'];break;
					case $value['level'] > 50:$value['level'] = '(B)'.$value['level'];break;
					default:$value['level'] = '(C)'.$value['level'];break;
				}

				$strexport.=$value['id']."\t";
				$strexport.=$value['mname']."\t";
				$strexport.=$value['title']."\t";
				$strexport.=$value['attribute']."\t";
				$strexport.=$value['type']."\t";
				$strexport.=$value['level_type']."\t";
				$strexport.=$value['words']."\t";
				$strexport.=$value['durationtime']."\t";
				$strexport.=$value['ordersex']."\t";
				$strexport.=$value['bgmid']==0?"无\t":"有\t";
				$strexport.=$value['ischose']==0?"否\t":"是\t";
				$strexport.=date("Y-m-d H:i:s",$value['releasetime'])."\t";
				$strexport.=$value['usemoney']."\t";
				$strexport.=$value['paytype']."\t";
				$strexport.=$value['uuid']."\t";
				$strexport.=$value['usersex']."\t";
				$strexport.=$value['level']."\t";
				$strexport.=$value['proportion']."\t";
				$strexport.=($value['usemoney']/2)."\t";
				$strexport.=date("Y-m-d H:i:s",$value['linkaudiotime'])."\r";
			}
		$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
			// $this->adminlog("导出订单数据");
		exit($strexport);
	}
	// 导出自媒体
	public function media()
	{
	set_time_limit(0);
			header("Content-type:application/vnd.ms-excel");
			header("Content-Disposition:filename=自媒体数据.xls");

			$strexport="自媒体编号\t账号编号\t名称\t手机号\t邮箱\t类型\t签约权限\t剩余字数\t签约主播\t创建时间\t订单数量\t订单总金额\t首单时间\t末单时间\t下单频率\r";
			// 查询数据
		$data = M('media')
		->field('id,media_name,media_tel,email,articles_name,wordnumber,uuid,create_time,wid')
		->select();
		foreach ($data as &$vo) {
			$vo['count'] = M('theorder')->where("mid={$vo['id']} AND (state = 3 or state = 4)")->count();
			$vo['sum'] = M('theorder')->where("mid={$vo['id']} AND (state = 3 or state = 4)")->sum("money+premium");
			$vo['frist'] = M('theorder')->field('createtime')->where("mid={$vo['id']} AND (state=3 or state=4)")->order("createtime asc")->find()['createtime'];
			$vo['end'] = M('theorder')->field('createtime')->where("mid={$vo['id']} AND (state = 3 or state = 4)")->order("createtime desc")->find()['createtime'];
			$vo['proportion'] = "无";
			$vo['nickname'] = "无";
			if ($vo['uuid'] != 0) {
				$user = M('member')->field('proportion,nickname')->where("uuid={$vo['uuid']}")->find();
				$vo['proportion'] = $user['proportion'];
				$vo['nickname'] = $user['nickname'];
			}
			$strexport.=$vo['id']."\t";
			$strexport.=$vo['wid']."\t";
			$strexport.=$vo['media_name']."\t";
			$strexport.=$vo['media_tel']."\t";
			$strexport.=$vo['email']."\t";
			$strexport.=$vo['articles_name']."\t";
			$strexport.=$vo['proportion'].'元/百字'."\t";
			$strexport.=$vo['wordnumber']."\t";
			$strexport.=$vo['nickname'].$vo['uuid']."\t";
			$strexport.=$vo['create_time']."\t";
			$strexport.=$vo['count']."\t";
			$strexport.=($vo['sum']*2)."\t";
			$strexport.=date("Y-m-d H:i:s",$vo['frist'])."\t";
			$strexport.=date("Y-m-d H:i:s",$vo['end'])."\t";
			$strexport.=round($vo['count']/floor(($vo['end']-$vo['frist'])/86400))."\r";
		}
			$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
			$this->adminlog("导出自媒体数据");
			exit($strexport);
	}
// 导出派单
	public function sendorder()
	{
			header("Content-type:application/vnd.ms-excel");
			header("Content-Disposition:filename=派单数据.xls");

			$strexport="日期\t订单总数\t开始发单时间\t结束发单时间\t平均单位小时订单量\t平均订单字数\t讲述类\t情感类\t演绎类\t新闻类\t在线主播数量\t未响应主播数\t接单总数\t平均交付时长\t最短交单时间\t最长交单时间\t保底主播接单总数\t保底主播人均接单数量\t保底主播接单人数\t保底主播平均交付时长\t保底主播最长交单时间\t最长交付主播\r";

			// 查询数据
			$today = strtotime(date("Y-m-d",time()));
			// echo $today;exit();
			$frist = "1520956800";//3-14
			while ($today>$frist) {
				$data[] = array("strat"=>($today-86400),"end"=>$today);
				$today -= 86400;
			}
			// p($data);exit();
			foreach ($data as $key => $value) {
				$strat = $value['strat'];
				$end = $value['end'];
				$where['issend'] = "1";
				$where['releasetime'] = array("BETWEEN",array($strat,$end));
				$db_theorder = M("theorder t");
				$true = "LENGTH(0+articleid) != LENGTH(articleid) and ";
				$strexport .= date("Y-m-d",$strat)."\t";
				$strexport .= $tx[$key]['订单总数'] = $db_theorder->where($where)->where($true."(state=3 or state=4)")->count()."\r";
				// $strexport .= $tx[$key]['开始发单时间'] = $db_theorder->where($where)->where($true."(state=3 or state=4)")->field("FROM_UNIXTIME(releasetime,'%Y-%m-%d %H:%i:%s') releasetime")->order("releasetime asc")->find()['releasetime']."\t";
				// $strexport .= $tx[$key]['结束发单时间'] = $db_theorder->where($where)->where($true."(state=3 or state=4)")->field("FROM_UNIXTIME(releasetime,'%Y-%m-%d %H:%i:%s') releasetime")->order("releasetime desc")->find()['releasetime']."\t";
				// echo $db_theorder->_sql();
				// $hour = ceil((strtotime($tx[$key]['结束发单时间'])-strtotime($tx[$key]['开始发单时间']))/3600);
				// $strexport .= $tx[$key]['平均单位小时订单量'] = round($tx[$key]['订单总数']/$hour)."\t";
				// $strexport .= $tx[$key]['平均订单字数'] = round($db_theorder->where($where)->where($true."(state=3 or state=4)")->avg('words'))."\t";
				// $strexport .= $tx[$key]['讲述类'] = $db_theorder->where($where)->where($true."type=0 and (state=3 or state=4)")->count()."\t";
				// $strexport .= $tx[$key]['情感类'] = $db_theorder->where($where)->where($true."type=1 and (state=3 or state=4)")->count()."\t";
				// $strexport .= $tx[$key]['演绎类'] = $db_theorder->where($where)->where($true."type=2 and (state=3 or state=4)")->count()."\t";
				// $strexport .= $tx[$key]['新闻类'] = $db_theorder->where($where)->where($true."type=3 and (state=3 or state=4)")->count()."\t";
				// $strexport .= $tx[$key]['在线主播数量'] = count($db_theorder->where($where)->where($true."(state=3 or state=4) and adminid=0")->distinct(true)->field("uuid")->select())."\t";
				// $strexport .= $tx[$key]['未响应主播数'] = count($db_theorder->join('__THEORDERINFO__ i ON t.id = i.oid',LEFT)->where($where)->where($true."state=6 and adminid=0")->distinct(true)->field("i.uuid")->select())."\t";
				// $strexport .= $tx[$key]['接单总数'] = $db_theorder->where($where)->where($true."(state=3 or state=4) and adminid=0")->count()."\t";
				// $strexport .= $tx[$key]['平均交付时长'] = date("i分s",$db_theorder->where($where)->where($true."(state=3 or state=4) and adminid=0")->avg('linkaudiotime-releasetime'))."\t";
				// $strexport .= $tx[$key]['最短交单时间'] = date("i分s",$db_theorder->where($where)->where($true."(state=3 or state=4) and adminid=0")->field("linkaudiotime-releasetime time")->order("linkaudiotime-releasetime asc")->find()['time'])."\t";
				// $strexport .= $tx[$key]['最长交单时间'] = date("i分s",$db_theorder->where($where)->where($true."(state=3 or state=4) and adminid=0")->field("linkaudiotime-releasetime time")->order("linkaudiotime-releasetime desc")->find()['time'])."\t";
				// $strexport .= $tx[$key]['保底主播接单总数'] = $db_theorder->where($where)->where($true."(state=3 or state=4) and adminid!=0")->count()."\t";
				// $allorder = $db_theorder->where($where)->where($true."(state=3 or state=4) and adminid!=0")->count();
				// $alladmin = count($db_theorder->where($where)->where($true."(state=3 or state=4) and adminid!=0")->distinct(true)->field("adminid")->select());
				// $strexport .= $tx[$key]['保底主播人均接单数量'] = round($allorder/$alladmin)."\t";
				// $strexport .= $tx[$key]['保底主播接单人数'] = $alladmin."\t";
				// $strexport .= $tx[$key]['保底主播平均交付时长'] = date("i分s",$db_theorder->where($where)->where($true."(state=3 or state=4) and adminid!=0")->avg('linkaudiotime-releasetime'))."\t";
				// $strexport .= $tx[$key]['保底主播最长交单时间'] = date("i分s",$db_theorder->where($where)->where($true."(state=3 or state=4) and adminid!=0")->field("linkaudiotime-releasetime time")->order("linkaudiotime-releasetime desc")->find()['time'])."\t";
				// $strexport .= $tx[$key]['最长交付主播'] = $db_theorder->join('__ADMIN__ a ON t.adminid = a.heard_admin_id',LEFT)->where($where)->where($true."(state=3 or state=4) and adminid!=0")->field("heard_adminname")->order("linkaudiotime-releasetime desc")->find()['heard_adminname']."\r";
			}
			$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
			$this->adminlog("导出派单数据");
			exit($strexport);
	}

	// 导出派单主播每日完成数量
	public function sendmember()
	{
		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition:filename=派单主播数据.xls");
		$today = strtotime(date("Y-m-d",time()));
		// $frist = "1520956800";//3-14
		$frist = "1531152000";//7-10

		while ($today>$frist) {
			$data[] = array("strat"=>($today-86400),"end"=>$today);
			$today -= 86400;
		}
		$strexport="";
		foreach ($data as $key => $value) {
			$strat = $value['strat'];
			$end = $value['end'];
			$where['pay_time'] = array("BETWEEN",array($strat,$end));
			$strexport.="日期\t".date("Y-m-d",$strat)."\r";
			$strexport.="编号\t单量\t连击\r";
			$sendorder = M('order')
			->field('user_id,count(user_id) count')
			->where("(type=3 or type=4) AND (status=6 or status=8) and adminid=0")
			->where($where)
			->order("count(user_id) desc")
			->group('user_id')
			->select();
			$date = date("Ymd",$strat);
			foreach ($sendorder as &$vo) {
				$vo['num'] = M("sendverify")->where(array("date"=>$date,"uuid"=>$vo['user_id']))->order("num desc")->find()['num'];
				$strexport.=$vo['user_id']."\t";
				$strexport.=$vo['count']."\t";
				$strexport.=$vo['num']."\r";
			}
		}
		$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
			$this->adminlog("导出派单主播数据");
		exit($strexport);
	}
	// 导出接过派单的主播数据
	public function senduser()
	{
		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition:filename=接过派单的主播数据.xls");
		$today = strtotime(date("Y-m-d",time()));
		$frist = "1520956800";//3-14
		$strexport.="编号\t能力\r";
		$where1['releasetime'] = array("BETWEEN",array($frist,$today));
		$true = "issend=1 and LENGTH(0+articleid) != LENGTH(articleid) and ";
		$db_theorder = M("theorder");
		$sendorder = $db_theorder->where($where1)->where($true."(state=3 or state=4) and adminid=0")->distinct(true)->field("uuid")->select();
		foreach ($sendorder as &$vo) {
			$soundtype = explode(",", M("member")->where(array("uuid"=>$vo['uuid']))->field("soundtype")->find()['soundtype']);
			$soundtype = str_replace(array(0,1,2,3,4,5),array("讲述类","情感类","演绎类","新闻类","英文类","自我介绍"),$soundtype);
			$soundname = implode(",", $soundtype);
			$data = M("data")->where(array("uuid"=>$vo['uuid']))->find();
			if ($data['bgm_audio_type'] == 1) {$soundname .= ",背景音";}
			if ($data['imitate_audio_type'] == 1) {$soundname .= ",模仿音";}
			$strexport.=$vo['uuid']."\t";
			$strexport.=$soundname."\r";
		}
		$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
		exit($strexport);
	}
	// 导出主播
	public function member()
	{
		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition:filename=主播特殊能力数据.xls");

		$strexport="主播编号\t昵称\t手机号\t性别\t年龄\t籍贯\t英语等级\t注册日期\t讲述类/情感类/演绎类/新闻类\t分数\t信用分\t是否绑定微信\t是否认证\t是否签约\t已提现金额\t账户余额\t总时长\t英文审核状态\t背景音审核状态\t模仿审核状态\t邀请人昵称\t完成订单数\r";
		// 查询数据
		$list = M("member m")
			->join("__WECHAT__ wc ON m.uuid = wc.uuid","LEFT")
			->join("__DATA__ d ON m.uuid = d.uuid")
			->field("m.uuid,m.nickname,m.username,m.sex,m.age,m.city,m.english,m.creationtime,m.soundtype,m.level,m.score,m.authentication,m.income,m.balance,alwaystime,wc.openid,(select count(w.uuid) from db_media w where m.uuid = w.uuid) iscollect,d.english_audio_type,d.bgm_audio_type,d.imitate_audio_type")
			->where("m.status = 9")
			->order('uuid asc')
			->select();

		$invite = M('invite')->select();
		//订单数
		$order_data = M('order')->where(['status'=>['in',[7,8]]])->group('user_id')->getField('user_id,count(id)',true);
		foreach ($list as &$row){
				$row['sex'] = $row['sex'] == 1 ? '男' : '女';
				switch ($row['english']) {
					case 0:$row['english'] = "入门";break;
					case 1:$row['english'] = "GET4";break;
					case 2:$row['english'] = "GET6";break;
					case 3:$row['english'] = "专业6级";break;
					case 4:$row['english'] = "专业8级";break;
					case 5:$row['english'] = "母语";break;
				}
				switch ($row['level']) {
					case $row['level'] > 80:$row['level'] = '(A)'.$row['level'];break;
					case $row['level'] > 50:$row['level'] = '(B)'.$row['level'];break;
					default:$row['level'] = '(C)'.$row['level'];break;
				}
				$row['openid'] = $row['openid'] == '' ? '未绑定' : '已绑定';
				$row['authentication'] = $row['authentication'] == 1 ? '是' : '否';
				$row['iscollect'] = $row['iscollect'] > 0 ? '是' : '否';
				switch ($row['english_audio_type']) {
					case 1:$row['english_audio_type'] = "已通过";break;
					case 2:$row['english_audio_type'] = "审核中";break;
					default:$row['english_audio_type'] = "未通过";break;
				}
				switch ($row['bgm_audio_type']) {
					case 1:$row['bgm_audio_type'] = "已通过";break;
					case 2:$row['bgm_audio_type'] = "审核中";break;
					default:$row['bgm_audio_type'] = "未通过";break;
				}
				switch ($row['imitate_audio_type']) {
					case 1:$row['imitate_audio_type'] = "已通过";break;
					case 2:$row['imitate_audio_type'] = "审核中";break;
					default:$row['imitate_audio_type'] = "未通过";break;
				}
				$row['invitename'] = "无";
				foreach ($invite as &$vo) {
					if($vo['uuid'] == $row['uuid']){
						$row['invitename'] = M('member')->where(array('uuid'=>$vo['inviteid']))->find()['nickname'];
					}
				}
				$soundtype = explode(",", $row['soundtype']);
				$soundtype = str_replace(array(0,1,2,3,4),array("讲述类","情感类","演绎类","新闻类",""),$soundtype);
				$row['soundtype'] = implode(",", $soundtype);
//				$row['ordercount'] = M('theorder')->where("(state = 3 or state = 4) and uuid = ".$row['uuid'])->count();
				$row['ordercount'] = $order_data[$row['uuid']]?$order_data[$row['uuid']]:'0';
				$strexport.=$row['uuid']."\t";
				$strexport.=$row['nickname']."\t";
				$strexport.=$row['username']."\t";
				$strexport.=$row['sex']."\t";
				$strexport.=$row['age']."\t";
				$strexport.=$row['city']."\t";
				$strexport.=$row['english']."\t";
				$strexport.=$row['creationtime']."\t";
				$strexport.=$row['soundtype']."\t";
				$strexport.=$row['level']."\t";
				$strexport.=$row['score']."\t";
				$strexport.=$row['openid']."\t";
				$strexport.=$row['authentication']."\t";
				$strexport.=$row['iscollect']."\t";
				$strexport.=($row['income']-$row['balance'])."\t";
				$strexport.=$row['balance']."\t";
				$strexport.=$row['alwaystime']."\t";
				$strexport.=$row['english_audio_type']."\t";
				$strexport.=$row['bgm_audio_type']."\t";
				$strexport.=$row['imitate_audio_type']."\t";
				$strexport.=$row['invitename']."\t";
				$strexport.=$row['ordercount']."\r";
		}
		$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
		$this->adminlog("导出主播详细数据");
		exit($strexport);
}

	// 导出主播

public function member_income()
{
	set_time_limit(0);
	ini_set('max_execution_time', '0');
	ini_set('memory_limit','500M');
	ob_end_clean();
	$filename = $this->time."主播收入数据";
	$db_theorder = M("theorder");
	$excelarr = array("主播编号","主播昵称","总接单量","腾讯接单量","腾讯项目收入","签约订单量","字数","元/每小时","签约单收入","时长(秒)","散单单量","散单收入","收入总计","总收入","余额");
	// 查询数据
	$userlist = M("member")->where("status>4 and level<50 and income>0")->field("uuid,nickname,authentication,proportion,income,balance")->select();
	$excellist = array();
	$where['releasetime'] = array("BETWEEN",array(strtotime($this->start),strtotime($this->end)));
	$orderlist = $db_theorder->where($where)->where("state = 4")->field("id,uuid,attribute,demand,money,premium,issend,originalaudio")->select();
	foreach ($orderlist as $key => $value) {
		$userorder[$value['uuid']][] = $value;
	}
	// p($userlist);exit();
	// echo count($userorder);exit();
	foreach ($userlist as $k => &$user){
		$user['ordercount'] = 0;//所有单
		$user['theordercount'] = 0;//普通单数量单
		$user['theorderincome'] = 0;//普通单收入
		$user['txordercount'] = 0;//派单数量
		$user['signordercount'] = 0;//签约单数量
		$user['signorderwordcount'] = 0;//签约单总字数
		$user['durationtime'] = 0;//wav时长
		if ($userorder[$user['uuid']]) {
			foreach ($userorder[$user['uuid']] as $key => &$order) {
				$user['ordercount'] += 1;
				if ($order['attribute']==0) {
					$user['theordercount'] += 1;
					if ($order['demand']==2) {
						$user['theorderincome'] += $order['money']+$order['premium'];
					}else{
						$user['theorderincome'] += $order['money'];
					}
				}
				if ($order['issend']==1) {
					$user['txordercount'] += 1;
				}
				if ($order['attribute']==1) {
					$user['signordercount'] += 1;
					$user['signorderwordcount'] += $order['words'];
					$user['durationtime'] += M("musictime")->where(array("oid"=>$order['id'],"type"=>1,"state"=>1))->find()['musictime']+0;
					// $user['durationtime'] += (int)json_decode(do_curl($order['originalaudio'].'?avinfo'),true)['format']['duration'];
				}
			}
		}
		$excellist[$k]['uuid'] = $user['uuid'];
		$excellist[$k]['nickname'] = $user['nickname'];
		$excellist[$k]['ordercount'] = $user['ordercount'];
		$excellist[$k]['txordercount'] = $user['txordercount'];
		$excellist[$k]['txordercount3'] = $user['txordercount']*3;
		$excellist[$k]['signordercount'] = $user['signordercount'];
		$excellist[$k]['signorderwordcount'] = $user['signorderwordcount'];
		$excellist[$k]['proportion'] = $user['proportion'];
		$excellist[$k]['proportionmoney'] = floor($user['durationtime']/3600)*$user['proportion'];
		$excellist[$k]['durationtime'] = $user['durationtime'];//时长
		$excellist[$k]['theordercount'] = $user['theordercount'];
		$excellist[$k]['theorderincome'] = $user['theorderincome'];
		$excellist[$k]['allmoney'] = ($user['txordercount']*3)+(floor($user['durationtime']/3600)*$user['proportion'])+$user['theorderincome'];
		$excellist[$k]['income'] = $user['income'];
		$excellist[$k]['balance'] = $user['balance'];
	}
	output_excel($filename.time(),$excelarr,$excellist);
}
public function member_order_income()
{
	set_time_limit(0);
	ini_set('max_execution_time', '0');
	ini_set('memory_limit','500M');
	ob_end_clean();
	$filename = $this->time."主播收入数据";
	$db_theorder = M("theorder");
	$excelarr = array("主播编号","主播昵称","腾讯接单量","腾讯项目收入","签约订单量","字数","元/每小时","签约单收入","时长(秒)","预约单","加急单","普通单","自选单","背景音单","散单收入");
	// 查询数据
	$userlist = M("member")->where("status>4 and level<50 and income>0")->field("uuid,nickname,authentication,proportion,income,balance")->select();
	$excellist = array();
	$where['releasetime'] = array("BETWEEN",array(strtotime($this->start),strtotime($this->end)));
	$orderlist = $db_theorder->where($where)->where("state = 4")->field("uuid,attribute,demand,money,premium,issend,originalaudio")->select();
	foreach ($orderlist as $key => $value) {
		$userorder[$value['uuid']][] = $value;
	}
	// p($userlist);exit();
	// echo count($userorder);exit();
	foreach ($userlist as $k => &$user){
		$user['ordercount'] = 0;//所有单
		$user['theordercount'] = 0;//普通单数量单
		$user['theorderincome'] = 0;//普通单收入
		$user['txordercount'] = 0;//派单数量
		$user['signordercount'] = 0;//签约单数量
		$user['signorderwordcount'] = 0;//签约单总字数
		$user['durationtime'] = 0;//wav时长
		$user['durationtime'] = 0;//预约单数量
		$user['durationtime'] = 0;//加急单数量
		$user['durationtime'] = 0;//普通单数量
		$user['durationtime'] = 0;//自选单
		$user['durationtime'] = 0;//背景音单
		if ($userorder[$user['uuid']]) {
			foreach ($userorder[$user['uuid']] as $key => &$order) {
				$user['ordercount'] += 1;
				if ($order['attribute']==0) {
					$user['theordercount'] += 1;
					if ($order['demand']==2) {
						$user['theorderincome'] += $order['money']+$order['premium'];
					}else{
						$user['theorderincome'] += $order['money'];
					}
				}
				if ($order['issend']==1) {
					$user['txordercount'] += 1;
				}
				if ($order['attribute']==1) {
					$user['signordercount'] += 1;
					$user['signorderwordcount'] += $order['words'];
					$user['durationtime'] += (int)json_decode(do_curl($order['originalaudio'].'?avinfo'),true)['format']['duration'];
				}
			}
		}
		$excellist[$k]['uuid'] = $user['uuid'];
		$excellist[$k]['nickname'] = $user['nickname'];
		$excellist[$k]['ordercount'] = $user['ordercount'];
		$excellist[$k]['txordercount'] = $user['txordercount'];
		$excellist[$k]['txordercount3'] = $user['txordercount']*3;
		$excellist[$k]['signordercount'] = $user['signordercount'];
		$excellist[$k]['signorderwordcount'] = $user['signorderwordcount'];
		$excellist[$k]['proportion'] = $user['proportion'];
		$excellist[$k]['proportionmoney'] = floor($user['durationtime']/3600)*$user['proportion'];
		$excellist[$k]['durationtime'] = $user['durationtime'];//时长

		$excellist[$k]['theordercount'] = $user['theordercount'];
		$excellist[$k]['theorderincome'] = $user['theorderincome'];
		$excellist[$k]['theorderincome'] = $user['theorderincome'];
		$excellist[$k]['theorderincome'] = $user['theorderincome'];
		$excellist[$k]['theorderincome'] = $user['theorderincome'];
		$excellist[$k]['theorderincome'] = $user['theorderincome'];
	}
	output_excel($filename.time(),$excelarr,$excellist);
}
// 导出派单文章
public function sendordercontent_old()
{
	header("Content-type:application/vnd.ms-excel");
	header("Content-Disposition:filename=派单文章数据.xls");

	$strexport="标题\t内容\r";
	// 查询数据
	$strat = "1526598000";
	$end = "1526616000";
	$where['issend'] = 1;
	$where['releasetime'] = array("BETWEEN",array($strat,$end));
	$list = M("theorder")->where($where)->where("(state=3 or state=4)")->select();

	foreach ($list as &$row){
		$row['content'] = $this->GetOss($row['content']);
		$strexport.=$row['title']."\t";
		$strexport.=$row['content']."\r";
	}
	$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
	// $this->adminlog("导出主播收入数据");
	exit($strexport);
}
public function sendordercontent()
{
	header("Content-type:application/vnd.ms-excel");
	header("Content-Disposition:filename=派单文章数据.xls");

	$strexport="标题\t内容\r";
	// 查询数据
	$where['pay_time'] = array("BETWEEN",array(strtotime($this->start),strtotime($this->end)));
	$list = M("order")->where($where)->where("(type=3 or type=4) and (status=5 or status=7)")->select();

	foreach ($list as &$row){
		$row['content'] = $this->GetOss($row['content']);
		$strexport.=$row['title']."\t";
		$strexport.=$row['content']."\r";
	}
	$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
	// $this->adminlog("导出主播收入数据");
	exit($strexport);
}
public function signorder()
	{
		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition:filename=签约单wav时长数据.xls");

		$strexport="主播编号\t时长\r";

		$db_theorder = M("theorder");
		$db_member = M("member");
		$where = " (state=3 or state=4) and attribute=1 ";
		$where2['releasetime'] = array("BETWEEN",array(1525104000,1526832000));
		$userlist = $db_member->where("authentication=1 and status=9 and id>10")->select();
		foreach ($userlist as $key => &$user) {
			$durationtime = 0;
			$where2['uuid'] = $user['uuid'];
			$orderlist = $db_theorder->where($where)->where($where2)->field("originalaudio")->select();
			foreach ($orderlist as $key => $value) {
				$durationtime += (int)json_decode(do_curl($value['originalaudio'].'?avinfo'),true)['format']['duration'];
			}
			$strexport.=$user['uuid']."\t";
			$strexport.=$durationtime."\r";
		}
		// p($order);exit();
		$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);
		$this->adminlog("导出签约单wav时长数据");
		exit($strexport);
	}
public function wemedia_source()
{
	set_time_limit(0);
	ini_set('max_execution_time', '0');
	ini_set('memory_limit','500M');
	ob_end_clean();
	$filename = $this->time."135来源账号数据";
	$db_theorder = M("theorder");
	$excelarr = array("编号","手机号","注册时间","余额","赠送","消费");
	// 查询数据
	$wemedialist = M("wemedia")->where("source=1 and status=2")->field("username,creationtime,wid,balance,grantmoney")->select();
	$excellist = array();
	$order_list = M("order")->where(array("type"=>1,"status"=>8))->select();
	foreach ($wemedialist as $k => &$wemedia){
		$wemedia['money'] = 0;//所有单
				$money = 0;
		foreach ($order_list as $key => $value) {
			if($value["media_tel"]==$wemedia['username']){
				$money = $value['price'];
				if ($value['requirement'] ==3) {
					$money = $value['price']+$value['increase_price'];
				}
				if ($value['bgm_id'] != 0) {
					$money += 10;
				}
			}

		}
		$excellist[$k]['wid'] = $wemedia['wid'];
		$excellist[$k]['username'] = $wemedia['username'];
		$excellist[$k]['creationtime'] = $wemedia['creationtime'];
		$excellist[$k]['balance'] = $wemedia['balance'];
		$excellist[$k]['grantmoney'] = $wemedia['grantmoney'];
		$excellist[$k]['money'] = $money*2;
	}
	output_excel($filename.time(),$excelarr,$excellist);
}

}